#!/usr/bin/env python
# -*- coding:utf-8 -*- 

from flask_restful import Resource, reqparse
from flask import jsonify
from flasgger import swag_from
from controller.passageInfoController import PassageInfoController
from utils import commons
from utils.response_code import RET

from flask import request

class PassageInfoResource(Resource):

    # get
    @swag_from('ymls/passageInfo_get.yml')
    def get(self, AutoID=None):
        if AutoID:
            kwargs = {
                'AutoID': AutoID
            }

            res = PassageInfoController.get(**kwargs)
            if res['code'] == RET.OK:
                return jsonify(code=res['code'], message=res['message'], data=res['data'])
            else:
                return jsonify(code=res['code'], message=res['message'], error=res['error'])

        parser = reqparse.RequestParser()
        parser.add_argument('PostAuthorID', type=str, location='args', required=False, help='PostAuthorID参数类型不正确或缺失')
        parser.add_argument('PostContent', type=str, location='args', required=False, help='PostContent参数类型不正确或缺失')
        parser.add_argument('PostTitle', type=str, location='args', required=False, help='PostTitle参数类型不正确或缺失')
        parser.add_argument('PostStatus', type=int, location='args', required=False, help='PostStatus参数类型不正确或缺失')
        parser.add_argument('PostType', type=str, location='args', required=False, help='PostType参数类型不正确或缺失')
        parser.add_argument('DeptType', type=str, location='args', required=False, help='DeptType参数类型不正确或缺失')
        parser.add_argument('UpVoteNum', type=int, location='args', required=False, help='UpVoteNum参数类型不正确或缺失')
        parser.add_argument('CommentNum', type=int, location='args', required=False, help='CommentNum参数类型不正确或缺失')
        parser.add_argument('LookNUM', type=int, location='args', required=False, help='LookNUM参数类型不正确或缺失')
        parser.add_argument('HeadlineEntities', type=str, location='args', required=False,
                            help='HeadlineEntities参数类型不正确或缺失')
        parser.add_argument('BodyEntities', type=str, location='args', required=False, help='BodyEntities参数类型不正确或缺失')
        parser.add_argument('IsDelete', type=int, location='args', required=False, help='IsDelete参数类型不正确或缺失')
        parser.add_argument('CreateTime', type=str, location='args', required=False, help='CreateTime参数类型不正确或缺失')
        parser.add_argument('ModifyTime', type=str, location='args', required=False, help='ModifyTime参数类型不正确或缺失')
        parser.add_argument('Page', type=int, location='args', required=False, help='Page参数类型不正确或缺失')
        parser.add_argument('Size', type=int, location='args', required=False, help='Size参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        res = PassageInfoController.get(**kwargs)
        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'], data=res['data'], totalPage=res['totalPage'],
                           totalCount=res['totalCount'])
        else:
            return jsonify(code=res['code'], message=res['message'], error=res['error'])

            # delete

    @swag_from('ymls/passageInfo_delete.yml')
    def delete(self, AutoID=None):
        if AutoID:
            kwargs = {
                'AutoID': AutoID
            }

        else:
            parser = reqparse.RequestParser()
            parser.add_argument('PostAuthorID', type=str, location='form', required=False,
                                help='PostAuthorID参数类型不正确或缺失')
            parser.add_argument('PostContent', type=str, location='form', required=False, help='PostContent参数类型不正确或缺失')
            parser.add_argument('PostTitle', type=str, location='form', required=False, help='PostTitle参数类型不正确或缺失')
            parser.add_argument('PostStatus', type=int, location='form', required=False, help='PostStatus参数类型不正确或缺失')
            parser.add_argument('PostType', type=str, location='form', required=False, help='PostType参数类型不正确或缺失')
            parser.add_argument('DeptType', type=str, location='form', required=False, help='DeptType参数类型不正确或缺失')
            parser.add_argument('UpVoteNum', type=int, location='form', required=False, help='UpVoteNum参数类型不正确或缺失')
            parser.add_argument('CommentNum', type=int, location='form', required=False, help='CommentNum参数类型不正确或缺失')
            parser.add_argument('LookNUM', type=int, location='form', required=False, help='LookNUM参数类型不正确或缺失')
            parser.add_argument('HeadlineEntities', type=str, location='form', required=False,help='HeadlineEntities参数类型不正确或缺失')
            parser.add_argument('BodyEntities', type=str, location='form', required=False,help='BodyEntities参数类型不正确或缺失')
            parser.add_argument('IsDelete', type=int, location='form', required=False, help='IsDelete参数类型不正确或缺失')
            parser.add_argument('CreateTime', type=str, location='form', required=False, help='CreateTime参数类型不正确或缺失')
            parser.add_argument('ModifyTime', type=str, location='form', required=False, help='ModifyTime参数类型不正确或缺失')
            parser.add_argument('AutoID', type=int, location='form', required=True, help='AutoID参数类型不正确或缺失')

            kwargs = parser.parse_args()
            kwargs = commons.put_remove_none(**kwargs)

        res = PassageInfoController.delete(**kwargs)
        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'])
        else:
            return jsonify(code=res['code'], message=res['message'], error=res['error'])

    # put
    @swag_from('ymls/passageInfo_put.yml')
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('AutoID', type=int, location='form', required=True, help='AutoID参数类型不正确或缺失')
        parser.add_argument('PostAuthorID', type=str, location='form', required=False, help='PostAuthorID参数类型不正确或缺失')
        parser.add_argument('PostContent', type=str, location='form', required=False, help='PostContent参数类型不正确或缺失')
        parser.add_argument('PostTitle', type=str, location='form', required=False, help='PostTitle参数类型不正确或缺失')
        parser.add_argument('PostStatus', type=int, location='form', required=False, help='PostStatus参数类型不正确或缺失')
        parser.add_argument('PostType', type=str, location='form', required=False, help='PostType参数类型不正确或缺失')
        parser.add_argument('DeptType', type=str, location='form', required=False, help='DeptType参数类型不正确或缺失')
        parser.add_argument('UpVoteNum', type=int, location='form', required=False, help='UpVoteNum参数类型不正确或缺失')
        parser.add_argument('CommentNum', type=int, location='form', required=False, help='CommentNum参数类型不正确或缺失')
        parser.add_argument('LookNUM', type=int, location='form', required=False, help='LookNUM参数类型不正确或缺失')
        parser.add_argument('HeadlineEntities', type=str, location='form', required=False, help='HeadlineEntities参数类型不正确或缺失')
        parser.add_argument('BodyEntities', type=str, location='form', required=False, help='BodyEntities参数类型不正确或缺失')
        parser.add_argument('IsDelete', type=int, location='form', required=False, help='IsDelete参数类型不正确或缺失')
        parser.add_argument('CreateTime', type=str, location='form', required=False, help='CreateTime参数类型不正确或缺失')
        parser.add_argument('ModifyTime', type=str, location='form', required=False, help='ModifyTime参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        res = PassageInfoController.update(**kwargs)
        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'])
        else:
            return jsonify(code=res['code'], message=res['message'], error=res['error'])

    # add
    @swag_from('ymls/passageInfo_post.yml')
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('PassageInfoList', type=str, location='form', required=False,
                            help='PassageInfoList参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        if kwargs.get('PassageInfoList'):
            res = PassageInfoController.add_list(**kwargs)

        else:
            parser.add_argument('PostAuthorID', type=str, location='form', required=True, help='PostAuthorID参数类型不正确或缺失')
            parser.add_argument('PostContent', type=str, location='form', required=True, help='PostContent参数类型不正确或缺失')
            parser.add_argument('PostTitle', type=str, location='form', required=True, help='PostTitle参数类型不正确或缺失')
            parser.add_argument('PostStatus', type=int, location='form', required=False, help='PostStatus参数类型不正确或缺失')
            parser.add_argument('PostType', type=str, location='form', required=False, help='PostType参数类型不正确或缺失')
            parser.add_argument('DeptType', type=str, location='form', required=False, help='DeptType参数类型不正确或缺失')
            parser.add_argument('UpVoteNum', type=int, location='form', required=False, help='UpVoteNum参数类型不正确或缺失')
            parser.add_argument('CommentNum', type=int, location='form', required=False, help='CommentNum参数类型不正确或缺失')
            parser.add_argument('LookNUM', type=int, location='form', required=False, help='LookNUM参数类型不正确或缺失')
            parser.add_argument('HeadlineEntities', type=str, location='form', required=False,help='HeadlineEntities参数类型不正确或缺失')
            parser.add_argument('BodyEntities', type=str, location='form', required=False,help='BodyEntities参数类型不正确或缺失')
            parser.add_argument('IsDelete', type=int, location='form', required=False, help='IsDelete参数类型不正确或缺失')
            parser.add_argument('CreateTime', type=str, location='form', required=False, help='CreateTime参数类型不正确或缺失')
            parser.add_argument('ModifyTime', type=str, location='form', required=False, help='ModifyTime参数类型不正确或缺失')

            kwargs = parser.parse_args()
            kwargs = commons.put_remove_none(**kwargs)

            res = PassageInfoController.add(**kwargs)

        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'], data=res['data'])
        else:
            return jsonify(code=res['code'], message=res['message'], error=res['error'])


# ------------------------------------------- Api漏洞缺陷 6 示例接口： 批量分配 ------------------------------------------
# class PassageInfoResource_vulnerability_6(Resource):
#     # put
#     @swag_from('ymls/passageInfo_put.yml')
#     def put(self):
#         parser = reqparse.RequestParser()
#         parser.add_argument('AutoID', type=int, location='form', required=True, help='AutoID参数类型不正确或缺失')
#         parser.add_argument('PostAuthorID', type=str, location='form', required=False, help='PostAuthorID参数类型不正确或缺失')
#         parser.add_argument('PostContent', type=str, location='form', required=False, help='PostContent参数类型不正确或缺失')
#         parser.add_argument('PostTitle', type=str, location='form', required=False, help='PostTitle参数类型不正确或缺失')
#         parser.add_argument('PostStatus', type=int, location='form', required=False, help='PostStatus参数类型不正确或缺失')
#         parser.add_argument('PostType', type=str, location='form', required=False, help='PostType参数类型不正确或缺失')
#         parser.add_argument('DeptType', type=str, location='form', required=False, help='DeptType参数类型不正确或缺失')
#         parser.add_argument('UpVoteNum', type=int, location='form', required=False, help='UpVoteNum参数类型不正确或缺失')
#         parser.add_argument('CommentNum', type=int, location='form', required=False, help='CommentNum参数类型不正确或缺失')
#         parser.add_argument('LookNUM', type=int, location='form', required=False, help='LookNUM参数类型不正确或缺失')
#         parser.add_argument('HeadlineEntities', type=str, location='form', required=False,
#                             help='HeadlineEntities参数类型不正确或缺失')
#         parser.add_argument('BodyEntities', type=str, location='form', required=False, help='BodyEntities参数类型不正确或缺失')
#         parser.add_argument('IsDelete', type=int, location='form', required=False, help='IsDelete参数类型不正确或缺失')
#         parser.add_argument('CreateTime', type=str, location='form', required=False, help='CreateTime参数类型不正确或缺失')
#         parser.add_argument('ModifyTime', type=str, location='form', required=False, help='ModifyTime参数类型不正确或缺失')
#
#         kwargs = parser.parse_args()
#         # print("1  ", kwargs)
#         kwargs = commons.put_remove_none(**kwargs)
#         # print("2  ", kwargs)
#
#         RE = {}
#
#         AutoID = request.form.get('AutoID')
#         RE["AutoID"] = AutoID
#         PostAuthorID = request.form.get('PostAuthorID')
#         RE["PostAuthorID"] = PostAuthorID
#         PostTitle = request.form.get('PostTitle')
#         RE["PostTitle"] = PostTitle
#
#         print("3  ", RE)

        # PostContent = request.form.get('PostContent')
        # RE["AutoID"] = AutoID
        # PostStatus = request.form.get('PostStatus')
        # RE["AutoID"] = AutoID
        # PostType = request.form.get('PostType')
        # RE["AutoID"] = AutoID
        # DeptType = request.form.get('DeptType')
        # RE["AutoID"] = AutoID
        # UpVoteNum = request.form.get('UpVoteNum')
        # RE["AutoID"] = AutoID
        # CommentNum = request.form.get('CommentNum')
        # RE["AutoID"] = AutoID
        # LookNUM = request.form.get('LookNUM')
        # RE["AutoID"] = AutoID
        # HeadlineEntities = request.form.get('HeadlineEntities')
        # RE["AutoID"] = AutoID
        # BodyEntities = request.form.get('BodyEntities')
        # RE["AutoID"] = AutoID
        # IsDelete = request.form.get('IsDelete')
        # RE["AutoID"] = AutoID
        # CreateTime = request.form.get('CreateTime')
        # RE["AutoID"] = AutoID
        # ModifyTime = request.form.get('ModifyTime')
        # RE["AutoID"] = AutoID

        # res = PassageInfoController.update_vulnerability_6(**kwargs)
        # if res['code'] == RET.OK:
        #     return jsonify(code=res['code'], message=res['message'])
        # else:
        #
        #     return jsonify(code=res['code'], message=res['message'], error=res['error'])
